package com.bwf.lgqingdan.gui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckedTextView;
import android.widget.ImageView;

import com.bwf.lgqingdan.R;
import com.bwf.lgqingdan.gui.adapter.base.BaseAdapterViewAdapter;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/11/17.
 */

public class PopSortListAdapter extends BaseAdapterViewAdapter<String> {
    public PopSortListAdapter(Context context) {
        super(context);
    }
    public void refresh(){
        this.selectedPosition = 0;
        notifyDataSetChanged();
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflaterView(R.layout.list_item_pop_sort, parent);
        return new ItemViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        ItemViewHolder viewHolder = (ItemViewHolder) holder;
        viewHolder.tvItemPopSort.setText(getItem(position));
        if(selectedPosition == position){
            viewHolder.tvItemPopSort.setChecked(true);
            viewHolder.imgItemPopSort.setVisibility(View.VISIBLE);
        }else{
            viewHolder.tvItemPopSort.setChecked(false);
            viewHolder.imgItemPopSort.setVisibility(View.GONE);
        }
    }

     class ItemViewHolder extends ViewHolder{
        @BindView(R.id.tv_item_pop_sort)
        CheckedTextView tvItemPopSort;
        @BindView(R.id.img_item_pop_sort)
        ImageView imgItemPopSort;

         ItemViewHolder(View view) {
             super(view);
            ButterKnife.bind(this, view);
        }
    }
    private int selectedPosition;

    public boolean setSelectedPosition(int selectedPosition) {
        if(this.selectedPosition == selectedPosition){
            return false;
        }
        this.selectedPosition = selectedPosition;
        notifyDataSetChanged();
        return true;
    }
}
